﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using DTO;

/// <summary>
/// Summary description for DuLieuDAO
/// </summary>
/// 
namespace DAO
{
    public class DuLieuDAO
    {
        
        public bool insert(DuLieuDTO dlDTO)
        {
            string strSQL = "Insert Into DULIEU(MaDuLieu,MaDichVu,MaTenDiaDiem,SoNha,MaDuong,MaPhuong,MaQuanHuyen,MaTinhThanh,KinhDo,ViDo,ChuThich)"
                + " values(" + dlDTO.MaDuLieu + "," + dlDTO.MaDichVu + "," + dlDTO.MaTenDiaDiem + ",'" + dlDTO.SoNha + "'," + dlDTO.MaDuong + "," + dlDTO.MaPhuong + "," + dlDTO.MaQuanHuyen + "," + dlDTO.MaTinhThanh + "," + dlDTO.KinhDo + "," + dlDTO.ViDo + ",'" + dlDTO.ChuThich + "')";
            return new dataProvider().executeNonQuery(strSQL);
        }
        public DataTable getDuLieuByDichVu(int MaDichVu)
        {
            string strSQL = "Select * from DULIEU Where MaDichVu =" + MaDichVu;
            return new dataProvider().executeQuery(strSQL);
        }
        public DataTable getDuLieuByDiaDiem(int MaTenDiaDiem)
        {
            string strSQL = "Select * from DULIEU Where MaTenDiaDiem =" + MaTenDiaDiem;
            return new dataProvider().executeQuery(strSQL);
        }
        
        public DataTable getDuLieuByQuan(int MaQuan)
        {
            string strSQL = "Select * from DULIEU Where MaQuan =" + MaQuan;
            return new dataProvider().executeQuery(strSQL);
        }
        public DataTable getDuLieuByTinhThanh(int MaTinhThanh)
        {
            string strSQL = "Select * from DULIEU Where  MaTinhThanh =" + MaTinhThanh;
            return new dataProvider().executeQuery(strSQL);
        }
        public DataTable getDuLieuByDuong(int MaDuong)
        {
            string strSQL = "Select * from DULIEU Where  MaDuong =" + MaDuong;
            return new dataProvider().executeQuery(strSQL);
        }
        public DataTable getDuLieuByPhuong(int MaPhuong)
        {
            string strSQL = "Select * from DULIEU Where  MaPhuong =" + MaPhuong;
            return new dataProvider().executeQuery(strSQL);
        }
        public DataTable getDulieuBy_DichVu_Duong_Quan(int MaDichVu, int MaTenDiaDiem, int MaDuong, int MaQuan)
        {
            //string strSQL = "Select * From DULIEU Where MaDichVu = " + MaDichVu + " and MaDuong = " + MaDuong + " and MaQuanHuyen = " + MaQuan ;
            //string strSQL = "Select * From DULIEU Where MaDichVu like " + MaDichVu + " and MaDuong like " + MaDuong + " and MaQuanHuyen like " + MaQuan;

            string strSQL = "SELECT DICHVU.TenDichVu, TENDIADIEM.TenDiaDiem, DUONG.TenDuong, PHUONG.TenPhuong, QUANHUYEN.TenQuanHuyen, DULIEU.SoNha, DULIEU.ChuThich, DULIEU.KinhDo, DULIEU.ViDo " +
                            "FROM DULIEU, QUANHUYEN, PHUONG, DUONG, DICHVU, TENDIADIEM " +
                            "WHERE DICHVU.MaDichVu=DULIEU.MaDichVu AND TENDIADIEM.MaTenDiaDiem=DULIEU.MaTenDiaDiem AND DUONG.MaDuong=DULIEU.MaDuong " + 
                            "AND PHUONG.MaPhuong=DULIEU.MaPhuong AND QUANHUYEN.MaQuanHuyen=DULIEU.MaQuanHuyen AND DULIEU.MaDichVu = " + MaDichVu;
            
            // Nếu có nhập vào tên địa điểm
            if (MaTenDiaDiem != -1)
            {
                strSQL += " and DULIEU.MaTenDiaDiem = " + MaTenDiaDiem ;
            }
            // Nếu có nhập tên đường vào
            if (MaDuong != -1)
            {
                strSQL += " and DULIEU.MaDuong = " + MaDuong;
            }

            // Nếu có nhập tên quận vào
            if (MaQuan != -1)
            {
                strSQL += " and DULIEU.MaQuanHuyen = " + MaQuan;
            }
            return new dataProvider().executeQuery(strSQL);
        }
    }
}

